﻿/*
 * Created by SharpDevelop.
 * User: amb
 * Date: 31/05/2014
 * Time: 12:09
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Text;
using System.Windows.Forms;
using System.IO;
using System.Xml;
using JdFormsDll;

namespace JdFormsDll
{
    public class MyFormProperties
    {
        private MyFormDecorator Decorator;

        public MyFormProperties(string filename, MyFormDecorator decorator)
        {
            Decorator = decorator;
            LoadProperties(filename);
        }

        public MyFormProperties(MyForm form)
        {
            LoadProperties(form);
        }

        public void SetProperties(MyForm form)
        {
            form.BackColor = this.BackColor;
            form.BackColorShadow = this.BackColorShadow;
            form.BorderColor = this.BorderColor;
            form.TextCaptionColor = this.TextCaptionColor;
            form.TextCaptionColorShadow = this.TextCaptionColorShadow;
            form.ForeColor = this.ForeColor;
            form.BorderStyle = this.BorderStyle;
            form.CaptionBorderRoundPercent = this.CaptionBorderRoundPercent;
            form.ColorsDifferencePercent = this.ColorsDifferencePercent;
            form.TextCaptionAlignment = this.TextCaptionAlignment;
            form.TextCaptionShadow = this.TextCaptionShadow;
            form.IsResizable = this.IsResizable;
            form.IsMoveable = this.IsMoveable;
            form.ShowClientBorder = this.ShowClientBorder;
            form.ShowCaptionBorder = this.ShowCaptionBorder;
            form.ShowTooltip = this.ShowTooltip;
            form.TextCaptionFont = this.TextCaptionFont;
        }

        private void LoadProperties(MyForm form)
        {
            this.BackColor = form.BackColor;
            this.BackColorShadow = form.BackColorShadow;
            this.BorderColor = form.BorderColor;
            this.TextCaptionColor = form.TextCaptionColor;
            this.TextCaptionColorShadow = form.TextCaptionColorShadow;
            this.ForeColor = form.ForeColor;
            this.BorderStyle = form.BorderStyle;
            this.CaptionBorderRoundPercent = form.CaptionBorderRoundPercent;
            this.ColorsDifferencePercent = form.ColorsDifferencePercent;
            this.TextCaptionAlignment = form.TextCaptionAlignment;
            this.TextCaptionShadow = form.TextCaptionShadow;
            this.IsResizable = form.IsResizable;
            this.IsMoveable = form.IsMoveable;
            this.ShowClientBorder = form.ShowClientBorder;
            this.ShowCaptionBorder = form.ShowCaptionBorder;
            this.ShowTooltip = form.ShowTooltip;
            this.TextCaptionFont = form.TextCaptionFont;
        }

        private void LoadProperties(string filename)
        {
            try
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(filename);
                XmlNode root = doc.SelectSingleNode("JdFormDecorator");
                if (root.HasChildNodes)
                {
                    this.BackColor = Decorator.S2C(Decorator.GetNode(root, "BackColor"));
                    this.BackColorShadow = Decorator.S2C(Decorator.GetNode(root, "BackColorShadow"));
                    this.BorderColor = Decorator.S2C(Decorator.GetNode(root, "BorderColor"));
                    this.TextCaptionColor = Decorator.S2C(Decorator.GetNode(root, "TextCaptionColor"));
                    this.TextCaptionColorShadow = Decorator.S2C(Decorator.GetNode(root, "TextCaptionColorShadow"));
                    this.ForeColor = Decorator.S2C(Decorator.GetNode(root, "ForeColor"));
                    this.BorderStyle = Decorator.B3S(Decorator.GetNode(root, "BorderStyle"));
                    this.CaptionBorderRoundPercent = Decorator.P(Decorator.GetNode(root, "CaptionBorderRoundPercent"));
                    this.ColorsDifferencePercent = Decorator.P(Decorator.GetNode(root, "ColorsDifferencePercent"));
                    this.TextCaptionAlignment = Decorator.CA(Decorator.GetNode(root, "TextCaptionAlignment"));
                    this.TextCaptionShadow = Decorator.SW(Decorator.GetNode(root, "TextCaptionShadow"));
                    this.IsResizable = Decorator.B(Decorator.GetNode(root, "IsResizable"));
                    this.IsMoveable = Decorator.B(Decorator.GetNode(root, "IsMoveable"));
                    this.ShowClientBorder = Decorator.B(Decorator.GetNode(root, "ShowClientBorder"));
                    this.ShowCaptionBorder = Decorator.B(Decorator.GetNode(root, "ShowCaptionBorder"));
                    this.ShowTooltip = Decorator.B(Decorator.GetNode(root, "ShowTooltip"));
                    this.TextCaptionFont = Decorator.S2F(Decorator.GetNode(root, "TextCaptionFont"));
                    root = null;
                    doc = null;
                }
            }
            catch { throw; }
        }

        public Color BackColor { get; private set; }
        public Color BackColorShadow { get; private set; }
        public Color BorderColor { get; private set; }
        public Color TextCaptionColor { get; private set; }
        public Color TextCaptionColorShadow { get; private set; }
        public Color ForeColor { get; private set; }
        public Border3DStyle BorderStyle { get; private set; }
        public Percent CaptionBorderRoundPercent { get; private set; }
        public Percent ColorsDifferencePercent { get; private set; }
        public ContentAlignment TextCaptionAlignment { get; private set; }
        public Shadow TextCaptionShadow { get; private set; }
        public bool IsResizable { get; private set; }
        public bool IsMoveable { get; private set; }
        public bool ShowClientBorder { get; private set; }
        public bool ShowCaptionBorder { get; private set; }
        public bool ShowTooltip { get; private set; }
        public Font TextCaptionFont { get; private set; }
    }
}
